﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Jumpton.SFA.Server.Entity;
using Jumpton.Persistent;

namespace Jumpton.SFA.Server.BusinessRule.CallRoute
{
    public class VisitFrequencyManager
    {
        public VisitFrequency Load(int id)
        {
            return (VisitFrequency)ObjectRow.Load(typeof(VisitFrequency), "this.ID=" + id);
        }

        public VisitFrequencyView LoadView(int id)
        {
            return (VisitFrequencyView)ObjectRow.Load(typeof(VisitFrequencyView), "this.ID=" + id);
        }

        /// <summary>
        /// 获取所有拜访频率
        /// </summary>
        /// <param name="DomainID"></param>
        /// <returns></returns>
        public ObjectTable LoadAll(decimal DomainID)
        {
            return new ObjectTable(typeof(VisitFrequencyView), "DomainID=" + DomainID);
        }

        public void Save(VisitFrequency obj)
        {
            if (obj != null)
            {
                obj.Save();
            }
        }
        /// <summary>
        /// 获取该域内未设定拜访频率的客户类型，无论是否处于无效状态
        /// </summary>
        /// <param name="DomainID"></param>
        /// <returns></returns>
        public global::System.Data.DataTable LoadCustomerType(decimal DomainID)
        {
            string Condition = string.Format(@"select t1.* from DictionaryItems t1,Dictionary t2 where T2.Code='" + DictionaryEnum.CustomerClass
                + "' and t1.DictionaryID = t2.dictionaryID and t1.DoMain_Id=t2.Domain_ID and t1.DictionaryItemid not in (select TypeID from VisitFrequency where DomainID={0})", DomainID);
            return Jumpton.Data.SqlData.OpenSql(Condition).Tables[0];
        }


    }
}
